﻿{extend name="base"/}
{block name="main"}
<div class="Hui-article">
    <article class="cl pd-20">
        <div class="n_tab_line">
            <a href="{:url('goods/goodsDelList')}" class="n_tab_list">回收站</a>
            <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px;display: none;" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
            <div class="cl"></div>
        </div>
                <div>
                   <div class="cl pd-5 bg-1 bk-gray mt-20">
                    <form class="Huiform" method="post" action="__CONF_SITE__admin/goods/goodsDelList" style="padding:15px;">
                        <div class="text-c"> 商品名称：
                            <input type="text" value="{$search_text}" name="search_text" placeholder=" 商品名称" style="width:250px" class="input-text">
                            <button class="btn btn-search radius" type="submit"><i class="Hui-iconfont">&#xe665;</i> 搜商品</button>
                        </div>
                    </form>
                        </div>
                    <div id="tab_demo" class="HuiTab" style="margin-top: 15px;">
                        <div class="tabBar clearfix">
                            <span {if condition="$status==''"} class="current" {/if} onclick="window.location.href='__CONF_SITE__admin/goods/goodslist'">全部</span>
                            <span {if condition="$status==1"} class="current" {/if} onclick="window.location.href='__CONF_SITE__admin/goods/goodslist&status=1'">出售中</span>
                            <span {if condition="$status==2"} class="current" {/if} onclick="window.location.href='__CONF_SITE__admin/goods/goodslist&status=2'">仓库中</span>
                            <span {if condition="$status==3"} class="current" {/if} onclick="window.location.href='__CONF_SITE__admin/goods/goodslist&status=3'">已售罄</span>
                            <span {if condition="$status==4"} class="current" {/if} onclick="window.location.href='__CONF_SITE__admin/goods/goodslist&status=4'">回收站</span>
                        </div>
                    </div>
                        <div class="cl pd-5 bg-1 bk-gray mt-20" style="border-bottom: 0;padding:10px;">
                        <span class="l"><a href="javascript:;" onclick="batchDelete()" class="btn btn-new radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a></span>
                    </div>
                    <div>
                        <table class="table table-border table-bordered table-bg table-hover table-sort" style="margin-top:0;">
                            <thead>
                            <tr class="text-c">
                                <th width="40"><input id="xs-all" name="" type="checkbox" value=""></th>
                                <th width="60">缩略图</th>
                                <th>产品名称</th>
                                <th>描述</th>
                                <th width="100">单价</th>
                                <th width="60">状态</th>
                                <th width="100">操作</th>
                            </tr>
                            </thead>
                            <tbody id="productTbody">
                            {volist name="result" id="r"}
                                <tr class="text-c va-m">
                                    <td><input name="sub" type="checkbox" value="{$r['goods_id']}"></td>
                                    <td><img width="60" height="60" class="radius" src="{$r['img_cover']}"></a></td>
                                    <td class="text-l">{$r['goods_name']}</td>
                                    <td class="text-l">{$r['introduction']}</td>
                                    <td><span class="price">{$r['price']}</span></td>
                                    <td class="td-status">
                                        <span class="label label-danger radius">回收站</span>
                                    </td>
                                    <td class="td-manage">
                                        <a style="text-decoration:none" onClick="goods_del_restore(this,'{$r.goods_id}')" href="javascript:;" title="恢复"><i class="Hui-iconfont">&#xe66b;</i></a>
                                        <a style="text-decoration:none" class="ml-5" onClick="goods_del_del(this,'{$r.goods_id}')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>
                                    </td>
                                </tr>
                            {/volist}
                            </tbody>
                        </table>
                        <div class="n_page_no">
                            {$page}
                        </div>
                    </div>
                </div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        $('#xs-all').click(function () {
            var xs_status = $('#xs-all').prop('checked');
            if (xs_status) {
                $("[name='sub']").prop('checked', true);
            }else{
                $("[name='sub']").prop('checked', false);
            }
        });
        $("[name='sub']").click(function () {
            var i = 0;
            var j = 0;
            $("[name='sub']").each(function () {
                var xs_stu = $(this).prop('checked');
                if (xs_stu) {
                    i++;
                }
                j++;
            });
            if (i == j) {
                $('#xs-all').prop('checked', true);
            } else {
                $('#xs-all').prop('checked', false);
            }
        });
    });
	/*
	 参数解释：
	 title	标题
	 url		请求的url
	 id		需要操作的数据id
	 w		弹出层宽度（缺省调默认值）
	 h		弹出层高度（缺省调默认值）
	 */
	/*回收站-单个删除*/
    function goods_del_del(obj,id){
        layer.confirm('确认要删除商品吗？',function(index){
            //此处请求后台程序，下方是成功后的处理……
            //后台处理
            $.ajax({
                type : "post",
                url : "{:url('goods/emptyDeleteGoods')}",
                data : {
                    "goods_ids" : id.toString()
                },
                success : function(data) {
                    if (data['code'] > 0) {
                        $(obj).parents("tr").remove();
                        layer.msg('操作成功!',{icon: 1,time:500});
                    }else{
                        layer.msg(data['message'], {icon: 2, time: 1000});
                    }
                }
            })
        });
    }
    /*回收站-批量删除*/
    function goods_del_del_pl(id){
        layer.confirm('确认要删除商品吗？',function(index){
            //此处请求后台程序，下方是成功后的处理……
            //后台处理
            $.ajax({
                type : "post",
                url : "{:url('goods/emptyDeleteGoods')}",
                data : {
                    "goods_ids" : id.toString()
                },
                success : function(data) {
                    if (data['code'] > 0) {
                        layer.msg('操作成功!',{icon: 1,time:500},function () {
                            window.location.reload();
                        });
                    }else{
                        layer.msg(data['message'], {icon: 2, time: 1000});
                    }
                }
            })
        });
    }
    //批量删除回收站数据
    function batchDelete() {
        var goods_ids= new Array();
        $("#productTbody input[type='checkbox']:checked").each(function() {
            if (!isNaN($(this).val())) {
                goods_ids.push($(this).val());
            }
        });
        if(goods_ids.length ==0){
            return false;
        }
        goods_del_del_pl(goods_ids);
    }
	/*商品回收站-恢复*/
    function goods_del_restore(obj,id){
        layer.confirm('确认要恢复商品吗？',function(index){
            //此处请求后台程序，下方是成功后的处理……
            //后台处理
            $.ajax({
                type : "post",
                url : "{:url('goods/regainGoodsDeleted')}",
                data : {
                    "goods_ids" : id
                },
                success : function(data) {
                    if (data['code'] > 0) {
                        $(obj).parents("tr").remove();
                        layer.msg('操作成功!',{icon: 1,time:500});
                    }else{
                        layer.msg(data['message'], {icon: 2, time: 1000});
                    }
                }
            })
        });
    }
</script>
{/block}